<template>
  <div>
    <h2>登录页面</h2>
    <br>
    <form @submit.prevent="login_function">
      <input v-model="username" placeholder="用户名" />
      <br>
      <input v-model="password" type="password" placeholder="密码" />
      <br>
      <button type="submit">登录</button>
    </form>
    token： {{ token }}
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { storeToRefs } from 'pinia';
import { useAllDateStore } from '@/stores/index.js';
import { useRouter, useRoute } from 'vue-router';
const router = useRouter()

const username = ref('');
const password = ref('');
const store = useAllDateStore();
const { token } = storeToRefs(store);

// 提交登录表单后的处理函数
const login_function = () => {
  // 判断用户名和密码是否正确
  if (username.value !== 'admin' || password.value !== '123456') {
    alert('用户名或密码错误');
    return;
  }
  // 登录成功后将 token 存储到 store 中
  store.setToken('your-token');
  // 登录成功后跳转到首页
  router.push('/home');
};
</script>